package cn.stylefeng.guns.modular.task.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.core.util.DateUtil;
import cn.stylefeng.guns.modular.basic.service.BasicCustomerService;
import cn.stylefeng.guns.modular.basic.service.BasicOperateService;
import cn.stylefeng.guns.modular.basic.service.BasicWarehouseService;
import cn.stylefeng.guns.modular.task.entity.TaskDetailed;
import cn.stylefeng.guns.modular.task.model.params.TaskDetailedParam;
import cn.stylefeng.guns.modular.task.model.params.TaskOrderParam;
import cn.stylefeng.guns.modular.task.model.result.TaskOrderResult;
import cn.stylefeng.guns.modular.task.service.TaskDetailedService;
import cn.stylefeng.guns.modular.task.service.TaskOrderService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;


/**
 * 作业明细表控制器
 *
 * @author zhucx
 * @Date 2021-06-08 09:20:26
 */
@Controller
@RequestMapping("/taskDetailed")
public class TaskDetailedController extends BaseController {

    private String PREFIX = "/task/taskDetailed";

    @Autowired
    private TaskDetailedService taskDetailedService;

    @Autowired
    private UserService userService;

    @Autowired
    private BasicOperateService basicOperateService;
    
    @Autowired
    private BasicCustomerService basicCustomerService;
    
    @Autowired
    private BasicWarehouseService basicWarehouseService;

    /**
     * 跳转到明细页面
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/taskDetailed.html";
    }

    /**
     * 跳转到合计明细页面
     */
    @RequestMapping("tosumdetailed")
    public String tosumdetailed() {
        return PREFIX + "/tosumdetailed.html";
    }

    /**
     * 跳转到 工人作业拣选日汇总页面
     */
    @RequestMapping("workerReportJx")
    public String workerReportJx(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();
    	model.addAttribute("basicOperatelist", basicOperateService.findAvailableList(deptId,deliverId,user.getOperateId()));
    	model.addAttribute("basicWarehouseList", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/workerReportJx.html";
    }

    /**
     * 查询 工人作业拣选日汇总列表
     */
    @ResponseBody
    @RequestMapping("/workerReportListJx")
    public LayuiPageInfo workerReportListJx(TaskDetailedParam taskDetailedParam,Long operateId,Long outCustomerId,String taskWork,String v8,String carModel,String startTimes,String endTime
    		,String condition 
    		,String type1,String type2,String type3,String type4,String type5,String type6,String type7,String type8,String type9) {
    	if(ToolUtil.isNotEmpty(taskWork)) {
    		if(taskWork.equals("卸车")) {
    			v8 = type1;
    		}
    		if(taskWork.equals("装车")) {
    			v8 = type2;
    		}
    		if(taskWork.equals("入库")) {
    			v8 = type3;
    		}
    		if(taskWork.equals("移库")) {
    			v8 = type4;
    		}
        	if(taskWork.equals("领料")) {
    			v8 = type5;
        	}
        	if(taskWork.equals("废料")) {
    			v8 = type6;
        	}
        	if(taskWork.equals("理库")) {
    			v8 = type7;
        	}
        	if(taskWork.equals("批量作业")) {
    			v8 = type8;
        	}
        	if(taskWork.equals("杂工")) {
    			v8 = type9;
        	}
    	}
    	if (ToolUtil.isNotEmpty(startTimes) && ToolUtil.isNotEmpty(endTime)) {
    		taskDetailedParam.setStartTime("'"+startTimes+"' and '"+endTime+"'");
		} else if (startTimes == null && endTime == null){
			startTimes = DateUtil.getDate();
			endTime = DateUtil.getDate();
    		taskDetailedParam.setStartTime("'"+startTimes+"' and '"+endTime+"'");
		}
    	User user = userService.getcurrentUser();
    	taskDetailedParam.setDeptId(user.getDeptId());
    	taskDetailedParam.setDeliverId(user.getDeliverId());
        return this.taskDetailedService.findworkerReportListJxPageBySpec(taskDetailedParam,condition, operateId,outCustomerId, taskWork,v8, carModel,user.getOperateId());
    }

    /**
     * 跳转到工人作业汇总页面
     */
    @RequestMapping("workerReport")
    public String workerReport(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();
    	model.addAttribute("basicCustomerList", basicCustomerService.findAvailableList(deptId,deliverId,user.getOperateId()));
    	model.addAttribute("basicOperatelist", basicOperateService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/workerReport.html";
    }

    /**
     * 查询工人作业汇总列表
     */
    @ResponseBody
    @RequestMapping("/workerReportList")
    public LayuiPageInfo workerReportList(TaskDetailedParam taskDetailedParam,Long operateId,Long outCustomerId,String taskWork,String v8,String carModel,String startTimes,String endTime
    		,String condition 
    		,String type1,String type2,String type3,String type4,String type5,String type6,String type7,String type8,String type9) {
    	if(ToolUtil.isNotEmpty(taskWork)) {
    		if(taskWork.equals("卸车")) {
    			v8 = type1;
    		}
    		if(taskWork.equals("装车")) {
    			v8 = type2;
    		}
    		if(taskWork.equals("入库")) {
    			v8 = type3;
    		}
    		if(taskWork.equals("移库")) {
    			v8 = type4;
    		}
        	if(taskWork.equals("领料")) {
    			v8 = type5;
        	}
        	if(taskWork.equals("废料")) {
    			v8 = type6;
        	}
        	if(taskWork.equals("理库")) {
    			v8 = type7;
        	}
        	if(taskWork.equals("批量作业")) {
    			v8 = type8;
        	}
        	if(taskWork.equals("杂工")) {
    			v8 = type9;
        	}
    	}
    	if (ToolUtil.isNotEmpty(startTimes) && ToolUtil.isNotEmpty(endTime)) {
    		taskDetailedParam.setStartTime("'"+startTimes+"' and '"+endTime+"'");
		} else if (startTimes == null && endTime == null){
			startTimes = DateUtil.getDate();
			endTime = DateUtil.getDate();
    		taskDetailedParam.setStartTime("'"+startTimes+"' and '"+endTime+"'");
		}
    	User user = userService.getcurrentUser();
    	taskDetailedParam.setDeptId(user.getDeptId());
    	taskDetailedParam.setDeliverId(user.getDeliverId());
        return this.taskDetailedService.findworkerReportListPageBySpec(taskDetailedParam,condition, operateId,outCustomerId, taskWork,v8, carModel,user.getOperateId());
    }

    /**
     * 跳转到工人作业单明细页面
     */
    @RequestMapping("grRtaskSummary")
    public String grRtaskSummary(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();
    	model.addAttribute("basicCustomerList", basicCustomerService.findAvailableList(deptId,deliverId,user.getOperateId()));
    	model.addAttribute("basicOperatelist", basicOperateService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/grRtaskSummary.html";
    }

    /**
     * 查询工人作业单明细列表
     */
    @ResponseBody
    @RequestMapping("/grRtaskSummaryList")
    public LayuiPageInfo grRtaskSummaryList(TaskDetailedParam taskDetailedParam,Long operateId,Long outCustomerId,String taskWork,String v8,String carModel,String startTimes,String endTime
    		,String condition 
    		,String type1,String type2,String type3,String type4,String type5,String type6,String type7,String type8,String type9) {
    	if(ToolUtil.isNotEmpty(taskWork)) {
    		if(taskWork.equals("卸车")) {
    			v8 = type1;
    		}
    		if(taskWork.equals("装车")) {
    			v8 = type2;
    		}
    		if(taskWork.equals("入库")) {
    			v8 = type3;
    		}
    		if(taskWork.equals("移库")) {
    			v8 = type4;
    		}
        	if(taskWork.equals("领料")) {
    			v8 = type5;
        	}
        	if(taskWork.equals("废料")) {
    			v8 = type6;
        	}
        	if(taskWork.equals("理库")) {
    			v8 = type7;
        	}
        	if(taskWork.equals("批量作业")) {
    			v8 = type8;
        	}
        	if(taskWork.equals("杂工")) {
    			v8 = type9;
        	}
    	}
    	if (ToolUtil.isNotEmpty(startTimes) && ToolUtil.isNotEmpty(endTime)) {
    		taskDetailedParam.setStartTime("'"+startTimes+"' and '"+endTime+"'");
		}else if (startTimes == null && endTime == null){
			startTimes = DateUtil.getDate();
			endTime = DateUtil.getDate();
    		taskDetailedParam.setStartTime("'"+startTimes+"' and '"+endTime+"'");
		}
    	User user = userService.getcurrentUser();
    	taskDetailedParam.setDeptId(user.getDeptId());
    	taskDetailedParam.setDeliverId(user.getDeliverId());
    	List<cn.stylefeng.guns.modular.task.model.result.grRtaskSummaryList> list = taskDetailedService.grRtaskSummaryList(taskDetailedParam,condition, operateId,outCustomerId, taskWork,v8, carModel,user.getOperateId());
    	LayuiPageInfo LayuiPageInfo = new LayuiPageInfo();
    	LayuiPageInfo.setData(list);
    	LayuiPageInfo.setCount(list.size());
        return LayuiPageInfo;
    }

    /**
     * 跳转到工人作业单汇总页面
     */
    @RequestMapping("grRtaskSum")
    public String grRtaskSum(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();
    	model.addAttribute("basicCustomerList", basicCustomerService.findAvailableList(deptId,deliverId,user.getOperateId()));
    	model.addAttribute("basicOperatelist", basicOperateService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/grRtaskSum.html";
    }

    /**
     * 查询工人作业单汇总列表
     */
    @ResponseBody
    @RequestMapping("/grRtaskSumList")
    public LayuiPageInfo grRtaskSumList(TaskDetailedParam taskDetailedParam,Long operateId,Long outCustomerId,String taskWork,String v8,String carModel,String startTimes,String endTime
    		,String condition 
    		,String type1,String type2,String type3,String type4,String type5,String type6,String type7,String type8,String type9) {
    	if(ToolUtil.isNotEmpty(taskWork)) {
    		if(taskWork.equals("卸车")) {
    			v8 = type1;
    		}
    		if(taskWork.equals("装车")) {
    			v8 = type2;
    		}
    		if(taskWork.equals("入库")) {
    			v8 = type3;
    		}
    		if(taskWork.equals("移库")) {
    			v8 = type4;
    		}
        	if(taskWork.equals("领料")) {
    			v8 = type5;
        	}
        	if(taskWork.equals("废料")) {
    			v8 = type6;
        	}
        	if(taskWork.equals("理库")) {
    			v8 = type7;
        	}
        	if(taskWork.equals("批量作业")) {
    			v8 = type8;
        	}
        	if(taskWork.equals("杂工")) {
    			v8 = type9;
        	}
    	}
    	if (ToolUtil.isNotEmpty(startTimes) && ToolUtil.isNotEmpty(endTime)) {
    		taskDetailedParam.setStartTime("'"+startTimes+"' and '"+endTime+"'");
		}else if (startTimes == null && endTime == null){
			startTimes = DateUtil.getDate();
			endTime = DateUtil.getDate();
    		taskDetailedParam.setStartTime("'"+startTimes+"' and '"+endTime+"'");
		}
    	User user = userService.getcurrentUser();
    	taskDetailedParam.setDeptId(user.getDeptId());
    	taskDetailedParam.setDeliverId(user.getDeliverId());
    	List<cn.stylefeng.guns.modular.task.model.result.grRtaskSummaryList> list = taskDetailedService.grRtaskSumList(taskDetailedParam,condition, operateId,outCustomerId, taskWork,v8, carModel,user.getOperateId());
    	LayuiPageInfo LayuiPageInfo = new LayuiPageInfo();
    	LayuiPageInfo.setData(list);
    	LayuiPageInfo.setCount(list.size());
        return LayuiPageInfo;
    }

    @Autowired
    private TaskOrderService taskOrderService;

    /**
     * 跳转到项目作业单明细页面
     */
    @RequestMapping("tooperateTaskList")
    public String tooperateTaskList(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();
    	model.addAttribute("basicCustomerList", basicCustomerService.findAvailableList(deptId,deliverId,user.getOperateId()));
    	model.addAttribute("basicOperatelist", basicOperateService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/operateTaskList.html";
    }

    /**
     * 查询项目作业单明细列表
     */
    @ResponseBody
    @RequestMapping("/operateTaskList")
    public LayuiPageInfo operateTaskList(TaskOrderParam taskOrderParam,String startTime,String endTime
    		,String condition 
    		,String type1,String type2,String type3,String type4,String type5,String type6,String type7,String type8,String type9) {
    	if(ToolUtil.isNotEmpty(taskOrderParam.getTaskWork())) {
    		if(taskOrderParam.getTaskWork().equals("卸车")) {
    			taskOrderParam.setV8(type1);
    		}
    		if(taskOrderParam.getTaskWork().equals("装车")) {
    			taskOrderParam.setV8(type2);
    		}
    		if(taskOrderParam.getTaskWork().equals("入库")) {
    			taskOrderParam.setV8(type3);
    		}
    		if(taskOrderParam.getTaskWork().equals("移库")) {
    			taskOrderParam.setV8(type4);
    		}
        	if(taskOrderParam.getTaskWork().equals("领料")) {
        		taskOrderParam.setV8(type5);
        	}
        	if(taskOrderParam.getTaskWork().equals("废料")) {
        		taskOrderParam.setV8(type6);
        	}
        	if(taskOrderParam.getTaskWork().equals("理库")) {
        		taskOrderParam.setV8(type7);
        	}
        	if(taskOrderParam.getTaskWork().equals("批量作业")) {
        		taskOrderParam.setV8(type8);
        	}
        	if(taskOrderParam.getTaskWork().equals("杂工")) {
        		taskOrderParam.setV8(type9);
        	}
    	}
    	if (ToolUtil.isNotEmpty(startTime) && ToolUtil.isNotEmpty(endTime)) {
			taskOrderParam.setCreateTimes("'"+startTime+"' and '"+endTime+"'");
		}else if (startTime == null && endTime == null){
			startTime = DateUtil.getDate();
			endTime = DateUtil.getDate();
			taskOrderParam.setCreateTimes("'"+startTime+"' and '"+endTime+"'");
		}
    	User user = userService.getcurrentUser();
    	taskOrderParam.setDeliverId(user.getDeliverId());
    	taskOrderParam.setDeptId(user.getDeptId());
    	List<TaskOrderResult> list = taskOrderService.operateTaskList(taskOrderParam,condition,user.getOperateId());
    	LayuiPageInfo LayuiPageInfo = new LayuiPageInfo();
    	LayuiPageInfo.setData(list);
    	LayuiPageInfo.setCount(list.size());
        return LayuiPageInfo;
    }
    /**
     * 跳转到项目作业单汇总页面
     */
    @RequestMapping("tooperateTaskSum")
    public String tooperateTaskSum(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();
    	model.addAttribute("basicCustomerList", basicCustomerService.findAvailableList(deptId,deliverId,user.getOperateId()));
    	model.addAttribute("basicOperatelist", basicOperateService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/operateTaskSum.html";
    }

    /**
     * 查询项目作业单汇总列表
     */
    @ResponseBody
    @RequestMapping("/operateTaskSum")
    public LayuiPageInfo operateTaskSum(TaskOrderParam taskOrderParam,String startTime,String endTime
    		,String condition 
    		,String type1,String type2,String type3,String type4,String type5,String type6,String type7,String type8,String type9) {
    	if(ToolUtil.isNotEmpty(taskOrderParam.getTaskWork())) {
    		if(taskOrderParam.getTaskWork().equals("卸车")) {
    			taskOrderParam.setV8(type1);
    		}
    		if(taskOrderParam.getTaskWork().equals("装车")) {
    			taskOrderParam.setV8(type2);
    		}
    		if(taskOrderParam.getTaskWork().equals("入库")) {
    			taskOrderParam.setV8(type3);
    		}
    		if(taskOrderParam.getTaskWork().equals("移库")) {
    			taskOrderParam.setV8(type4);
    		}
        	if(taskOrderParam.getTaskWork().equals("领料")) {
        		taskOrderParam.setV8(type5);
        	}
        	if(taskOrderParam.getTaskWork().equals("废料")) {
        		taskOrderParam.setV8(type6);
        	}
        	if(taskOrderParam.getTaskWork().equals("理库")) {
        		taskOrderParam.setV8(type7);
        	}
        	if(taskOrderParam.getTaskWork().equals("批量作业")) {
        		taskOrderParam.setV8(type8);
        	}
        	if(taskOrderParam.getTaskWork().equals("杂工")) {
        		taskOrderParam.setV8(type9);
        	}
    	}
    	if (ToolUtil.isNotEmpty(startTime) && ToolUtil.isNotEmpty(endTime)) {
			taskOrderParam.setCreateTimes("'"+startTime+"' and '"+endTime+"'");
		}else if (startTime == null && endTime == null){
			startTime = DateUtil.getDate();
			endTime = DateUtil.getDate();
			taskOrderParam.setCreateTimes("'"+startTime+"' and '"+endTime+"'");
		}
    	User user = userService.getcurrentUser();
    	taskOrderParam.setDeliverId(user.getDeliverId());
    	taskOrderParam.setDeptId(user.getDeptId());
    	List<TaskOrderResult> list = taskOrderService.operateTaskSum(taskOrderParam,condition,user.getOperateId());
    	LayuiPageInfo LayuiPageInfo = new LayuiPageInfo();
    	LayuiPageInfo.setData(list);
    	LayuiPageInfo.setCount(list.size());
        return LayuiPageInfo;
    }

    /**
     * 新增页面
     *
     * @author zhucx
     * @Date 2021-06-08
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/taskDetailed_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zhucx
     * @Date 2021-06-08
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/taskDetailed_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zhucx
     * @Date 2021-06-08
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(TaskDetailedParam taskDetailedParam) {
        this.taskDetailedService.add(taskDetailedParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zhucx
     * @Date 2021-06-08
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(TaskDetailedParam taskDetailedParam) {
        this.taskDetailedService.update(taskDetailedParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zhucx
     * @Date 2021-06-08
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(TaskDetailedParam taskDetailedParam) {
        this.taskDetailedService.delete(taskDetailedParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zhucx
     * @Date 2021-06-08
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(TaskDetailedParam taskDetailedParam) {
        TaskDetailed detail = this.taskDetailedService.getById(taskDetailedParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询明细列表
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(TaskDetailedParam taskDetailedParam,String condition ) {
        return this.taskDetailedService.findPageBySpec(taskDetailedParam,condition);
    }

    /**
     * 查询合计明细列表
     */
    @ResponseBody
    @RequestMapping("/sumTaskDetailed")
    public LayuiPageInfo sumTaskDetailed(TaskDetailedParam taskDetailedParam,String condition ) {
        return this.taskDetailedService.findSumPageBySpec(taskDetailedParam,condition);
    }

}


